package org.watchrecords.pages;

import org.apache.wicket.PageParameters;
import org.apache.wicket.authentication.panel.SignInPanel;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.PageLink;
import org.watchrecords.WatchRecordsSession;
import org.watchrecords.annotations.SiteTitle;
import org.watchrecords.constants.Permission;
import org.watchrecords.dbo.User;
import org.watchrecords.elements.LoginPanel;
import org.watchrecords.elements.Sidebar;

import com.google.inject.Inject;

public class BasicPage extends WebPage {
    @Inject @SiteTitle private String siteTitle;
    
    public BasicPage(PageParameters pageParameters) {
        super(pageParameters);
        add(new PageLink<Object>("mainPageLink", MainPage.class).add(new Label("siteTitle", siteTitle)));
        add(new Label("pageTitle", siteTitle));
        add(new Sidebar("sidebar"));
        
        User user = getUser();
        
        if (user != null) {
            add(new LoginPanel("login", user));
        }
        else {
            add(new SignInPanel("login", false));
        }
    }
    
    protected User getUser() {
        return ((WatchRecordsSession) getSession()).getUser();
    }

    protected String getSiteTitle() {
        return siteTitle;
    }
    
    protected boolean haveAnyPermission(Permission... permissions) {
        return ((WatchRecordsSession) getSession()).haveAnyPermission(permissions);
    }
}
